<?php
/*
  [EWEISHOP] Copyright(C) 2017 Elinkint Inc.
  This is NOT a freeware, use is subject to license terms
   
  MiniProgramEncryptor.php 2018-05-25 17:34 cunx $
   
*/

namespace common\library\wechat\miniprogram;

use common\component\wechat\Wechat;
use common\library\wechat\WechatApi;

/**
 * 微信小程序消息解密
 * Class MiniProgramEncryptor
 * @package common\library\wechat\miniprogram
 * @author cunx
 */
class MiniProgramEncryptor extends WechatApi
{
    public static $apiType = 'miniProgram';
    /**
     * 微信小程序消息解密
     * @param string $session_key  用户的会话密钥
     * @param string $iv           加密算法的初始向量
     * @param string $encryptData  包括敏感数据在内的完整用户信息的加密数据
     * @return array|bool|void
     * @link https://developers.weixin.qq.com/miniprogram/dev/api/getPhoneNumber.html 例子:手机号码解密
     * @author cunx
     */
    public static function decryptData(string $session_key,string $iv,string $encryptData){
        try{
            $result = self::getInstance()->encryptor->decryptData($session_key, $iv, $encryptData);
        }catch(\Exception $result){}
        return Wechat::apiError($result);
    }
}